package com.cqndt.disaster.device.controller;

import java.util.Map;
import java.util.List;
import com.cqndt.disaster.device.vo.SearchVo;
import com.cqndt.disaster.device.util.Result;
import com.cqndt.disaster.device.vo.TabSensorVo;
import com.cqndt.disaster.device.vo.DeviceScaleVo;
import com.cqndt.disaster.device.vo.DeviceInProjectVo;
import com.cqndt.disaster.device.domain.TabWarnSetting;
import com.cqndt.disaster.device.service.AnalysisService;
import com.cqndt.disaster.device.service.TabDeviceService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020-8-26
 * @说明   数据分析
 **/
@RestController
@RequestMapping("/analysis")
public class DataAnalysisController {
    @Autowired
    private TabDeviceService tabDeviceService;
    @Autowired
    private AnalysisService analysisService;

    /**
     * @param monitorNo 布置点编号
     * @return 安装布置点对应的传感器
     **/
    @PostMapping(value="listTabSensor")
    public Result listTabSensor(String monitorNo){
        List<TabSensorVo> list = tabDeviceService.getSensorByMonitorNo(monitorNo);
        Result result = new Result();
        result.setData(list);
        return result;
    }
    /**
     * @param sensorNo 传感器编号
     * @param sensorType 传感器编号
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 数据曲线
     **/
    @PostMapping(value="echart")
    public Result echart(SearchVo vo){
        Result result = new Result();
        Map<String, Object> map = analysisService.selecteChart(vo);
        result.setData(map);
        return result;
    }
    /**
     * @param sensorNo 传感器编号
     * @param sensorType 传感器类型
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 数据曲线2
     **/
    @PostMapping(value="echart2")
    public Result echart2(SearchVo vo){
        Result result = new Result();
        Map<String,Object> map = analysisService.selecteChart2(vo);
        result.setData(map);
        return result;
    }
    /**
     * @param projectId
     * @return 项目下所有的设备
     **/
    @PostMapping(value="selectDeviceByProjectId")
    public Result selectDeviceByProjectId(String projectId) {
        Result result = new Result();
        List<DeviceInProjectVo> list = analysisService.selectDeviceByProjectId(projectId);
        result.setData(list);
        return result;
    }
    /**
     * @param sensorNo 传感器编号
     * @return 根据传感器编号获取相应的阈值
     **/
    @PostMapping(value="getSettingBySensorNo")
    public Result getSettingBySensorNo(String sensorNo){
        TabWarnSetting setting = analysisService.getSettingBySensorNo(sensorNo);
        Result result = new Result();
        result.setData(setting);
        return result;
    }
    /**
     * @param deviceType
     * @param monitorNo
     * @return 通过设备类型查询设备类型
     **/
    @PostMapping(value="selectDeviceType")
    public Result selectDeviceType(Integer deviceType,String monitorNo) {
        return tabDeviceService.selectDeviceType(deviceType, monitorNo);
    }
    /**
     * @param projectId 项目id
     * @return 查询设备类型
     **/
    @PostMapping("selectType")
    public Result selectType(String projectId) {
        return tabDeviceService.selectType(projectId);
    }
    /**
     * @return 查询传感器类型
     **/
    @PostMapping("selectSensorType")
    public Result selectSensorType() {
        return tabDeviceService.selectSensorType();
    }
    /**
     * @param typeId 设备类型id
     * @param scale 刻度
     * @return 修改刻度
     **/
    @PostMapping("updateScale")
    public Result updateScale(Integer typeId, String scale) {
        return tabDeviceService.updateScale(typeId, scale);
    }
    /**
     * @param projectId
     * @return 获取当前项目下刻度列表
     **/
    @PostMapping("getSensorType")
    public Result getSensorType(String projectId) {
    	Result result = new Result();
        List<DeviceScaleVo> list = analysisService.getSensorType(projectId);
        result.setData(list);
        return result;
    }
}